package com.cn.jdia.tas.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cn.jdia.tas.model.Mobileversion;
import com.cn.jdia.tas.service.IMobileVersionService;
import com.google.gson.Gson;


@Controller
@RequestMapping("/control")
public class VersionController {
	
	@Resource
	private IMobileVersionService mobileversionService;
	
	@RequestMapping("/mobileversion")
	public String getVersion(HttpServletRequest request, HttpServletResponse response) throws IOException {

		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		Mobileversion latestVersion = mobileversionService.getLatestVersion();
		System.out.println("-----");
		System.out.println(latestVersion.getId());
		System.out.println(latestVersion.getVerInfo());
		System.out.println(latestVersion.getSysFilePath());
		System.out.println("-----");
		
		Map<String,Object> map=new HashMap<>();
		map.put("ver", latestVersion.getVerInfo());
		map.put("path", latestVersion.getSysFilePath());
		
		
		Gson gson=new Gson();
		
		out.write(gson.toJson(map));
		out.flush();
		out.close();

		return null;
	}
}
